package com.android.tea;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

import com.android.tea.data.SettingLoader;
import com.android.tea.util.Utils;

public class WelcomeActivity extends Activity {
	private ProgressBar progressBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.startup);
		progressBar = (ProgressBar)findViewById(R.id.progressBar1);
		
		startup();
		if(!SettingLoader.hasregister(this)) {
			Utils.registerAlarm(this);
			SettingLoader.setRegister(this,true);
		}
	}

	
	
	private void startup() {
		new AsyncTask<Void, Integer, Long>() {

			@Override
			protected Long doInBackground(Void... params) {
				try {
					Thread.sleep(3500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return null;
			}

			@Override
			protected void onPostExecute(Long result) {
				progressBar.setVisibility(View.INVISIBLE);
				boolean firstLaunch = SettingLoader.getFirstLaunch(WelcomeActivity.this);
				Intent intent = null;
				if(firstLaunch) {
					SettingLoader.setFirstLaunch(WelcomeActivity.this, false);
					intent = new Intent(WelcomeActivity.this,GuideActivity.class);
				}else {
					intent = new Intent(WelcomeActivity.this,BaseTabActivity.class);
				}
				startActivity(intent);
				finish();
				super.onPostExecute(result);
			}

			@Override
			protected void onPreExecute() {
				progressBar.setVisibility(View.VISIBLE);
				super.onPreExecute();
			}
			
			
		}.execute();
		
	}
}
